/*
 * User: user
 * Date: 22/12/2007
 * Time: 11:37:52
 */
package org.conann.metadata.records;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 Represents a method parameter.
 Complements java.lang.reflect package with a class that represents a method paramter in a type-safe and convenient way.
 */
public class MethodParameter extends Parameter<Method> {

    private final Method method;

    public MethodParameter(Method method, int index) {
        super(index, method.getParameterTypes()[index]);
        checkNotNull(method);
        Class<?>[] parameterTypes = method.getParameterTypes();
        checkArgument(parameterTypes.length > 0);
        checkArgument(parameterTypes.length >= index);
        this.method = method;
    }

    public Annotation[] getAnnotations() {
        return method.getParameterAnnotations()[getIndex()];
    }

    public Method getMethod() {
        return method;
    }

    @Override
    protected Method getElement() {
        return method;
    }

    @Override
    protected String getElementName() {
        return method.getName();
    }
}